

******* Preliminary Study Results ******* 
*			 					*
* Data Date = November 10 2020  *
*							  	*
*							  	*
*							  	*
*******************************

clear all
set more off

local date November10
local mdate November10

********************
*Set Person Working*
*Change this to your name!!!!!
********************
*global carolina 0
*global emily 1
global emily 1
global carolina 0

*Carolina's Computer*
if $carolina ==1  {
cap cd "E:\Dropbox\Dropbox\Carolina-Emily-Project\Data\Study\"

}
*Emily's Computer*
if $emily ==1  {
cap cd "~/Dropbox/SourceContent/Data/Study/"
} 

*********************
*Load Files*
*********************
if $emily ==1 {

import delimited "Qualtrics`date'/MTurkScreen_Democrat.csv", varnames(1) clear
keep amazonidentifier
rename amazonidentifier aid
bysort aid: keep if _n==1
gen mturk_democrat=1
tempfile id_dem
save `id_dem'

import delimited "Qualtrics`date'/MTurkScreen_Republican.csv", varnames(1) clear
keep amazonidentifier
rename amazonidentifier aid
bysort aid: keep if _n==1
gen mturk_republican=1
tempfile id_repub
save `id_repub'

import delimited "Qualtrics`date'/MTurkScreen_Conservative.csv", varnames(1) clear
keep amazonidentifier
rename amazonidentifier aid
bysort aid: keep if _n==1
gen mturk_conservative=1
tempfile id_conservative
save `id_conservative'

import delimited "Qualtrics`date'/MTurkScreen_Liberal.csv", varnames(1) clear 
keep amazonidentifier
rename amazonidentifier aid
bysort aid: keep if _n==1
gen mturk_liberal=1
tempfile id_liberal
save `id_liberal'
 
}

if $emily ==1 {
clear all
import delimited "Qualtrics`date'/Republican_`date'.csv", varnames(1) 
gen democrat=0
gen mturk=0
drop if _n<81
tempfile repub
save `repub'

clear all
import delimited "Qualtrics`date'/MTurk_`date'.csv", varnames(1) 
*gen democrat=0
gen mturk=1
drop if _n<82
merge m:1 aid using `id_dem'
drop if _m==2
drop _m
replace mturk_democrat=0 if mturk_democrat==.
merge m:1 aid using `id_repub'
drop if _m==2
drop _m
replace mturk_republican=0 if mturk_republican==.
merge m:1 aid using `id_conservative'
drop if _m==2
drop _m
replace mturk_conservative=0 if mturk_conservative==.
merge m:1 aid using `id_liberal'
drop if _m==2
drop _m
replace mturk_liberal=0 if mturk_liberal==.
tempfile mturk
save `mturk'

clear all
import delimited "Qualtrics`date'/Democrat_`date'.csv", varnames(1) 
gen democrat=1
gen mturk=0
drop if _n<81
append using `repub'
append using `mturk'

}
 
drop if finished=="False"
keep if status=="IP Address"

rename democrat recruitdemocrat
 
destring randomid, replace
drop if randomid==.
keep if aid!=""

//Take out test responses
sort startdate
gen date=substr(startdate,6,5)
drop if date=="10-07" | date=="10-08" | date=="10-09" | date=="10-10" ///
	| date=="10-11" | date=="10-12"  | date=="10-13" | date=="10-14" | date=="10-15"
drop if aid=="A_WORKER_ID"

//Drop Carolina's test observation
drop if ipaddress=="128.100.177.38"

***Look at lottery winners before any screening***
rename q311 lotterywin_email
replace lotterywin_email=q51 if q51!=""
drop q51
tab lotterywin_email 

*IDENTIFY DUPLICATE RESPONDERS*
//Keep only one response from each IP Address
sort ipaddress startdate
bysort ipaddress: gen numbersurveys=_N
bysort ipaddress: gen n=_n==1


if $emily ==1  {
preserve
keep if numbersurveys>1 & mturk==0 
rename n firstentry
keep numbersurveys aid ipaddress startdate firstentry mturk
export excel using "Qualtrics`date'/DuplicateIDs_`date'.xlsx", firstrow(variables) replace
keep if firstentry==0
keep numbersurveys aid ipaddress mturk
export excel using "Qualtrics`date'/Dropped_DuplicateIDs_`date'.xlsx", firstrow(variables) replace
restore
}

gen duplicate = n==0 & mturk==0 

//drop remaining duplicates on aid
sort aid startdate
bysort aid: replace duplicate=1 if _n>1

drop n progress finished recordeddate responseid recipient* external distribution userlanguage

************************************************
*Initial Drop: No Consent, No Audio & Not U.S. Citizen
************************************************
***1.  Pre intervention variables***

//Drop if no consent 
if $emily ==1  {
preserve
keep if q11=="No" 
keep aid mturk
export excel using "Qualtrics`date'/NoConsent_`date'.xlsx", firstrow(variables) replace
restore
}

gen drop_consent=q11=="No"
drop q11 

//Drop if no audio connection
if $emily ==1  {
preserve
keep if q22=="No" 
keep aid mturk
export excel using "Qualtrics`date'/NoAudioCapability_`date'.xlsx", firstrow(variables) replace
restore
}

gen drop_audio=q22=="No"
drop q22 

//Drop if not a U.S. Citizen
if $emily ==1  {
preserve
keep if q31=="No" 
keep aid mturk
export excel using "Qualtrics`date'/NotUSCitizen_`date'.xlsx", firstrow(variables) replace
restore
}

gen drop_citizen=q31=="No"
drop q31  

************************************************
*Initial Drop: Party Inconsistencies - Recruitment*
************************************************
label variable q47 "Party"
replace q47="1" if q47=="Democrat"
replace q47="0" if q47=="Republican"
replace q47="2" if q47=="Other"
replace q47="2" if q47=="Independent"
destring q47, replace
label define party 1 "Democrat" 0 "Republican" 2 "Independent" , add 
label values q47 party
rename q47 democrat

*Resolve Party Conflicts in MTurk*
*Drop Party Conflicts*
//Both parties/Ideologies
if $emily ==1  {
preserve
keep if (mturk_republican==1 & mturk_democrat==1) ///
	| (mturk_liberal==1 & mturk_conservative==1) ///
	| (mturk_republican==1 & mturk_liberal==1) ///
	| (mturk_democrat==1 & mturk_conservative==1)
keep aid mturk mturk_republican mturk_democrat mturk_conservative mturk_liberal 
export excel using "Qualtrics`date'/BothPartiesorIdeology_MTurk_`date'.xlsx", firstrow(variables) replace
restore
}

drop if mturk_republican==1 & mturk_democrat==1
drop if mturk_conservative==1 & mturk_liberal==1
drop if mturk_republican==1 & mturk_liberal==1
drop if mturk_democrat==1 & mturk_conservative==1

replace recruitdemocrat=1 if mturk==1 & (mturk_democrat==1 | mturk_liberal==1)
replace recruitdemocrat=0 if mturk==1 & (mturk_republican==1 | mturk_conservative==1)

tab recruitdemocrat democrat

if $emily ==1  {

preserve
keep if recruitdemocrat==0 & democrat==1 
keep aid mturk
export excel using "Qualtrics`date'/RecruitedDemocratsAreRepublicans_`date'.xlsx", firstrow(variables) replace
restore

preserve
keep if recruitdemocrat==1 & democrat==0 
keep aid mturk
export excel using "Qualtrics`date'/RecruitedRepublicansAreDemocrats_`date'.xlsx", firstrow(variables) replace
restore

preserve
keep if recruitdemocrat==0 & mturk==1 & dem==1
keep aid mturk
export excel using "Qualtrics`date'/MTurkIndependents_`date'.xlsx", firstrow(variables) replace
restore
}

gen drop_inconsistent=(recruitdemocrat==0 & democrat==1 ) | ///
	(recruitdemocrat==1 & democrat==0 )

di _N //19,780

***************************************************************************
***Drop 1: Duplicates - Multiple Attempts**
***************************************************************************

drop if duplicate==1

tempfile noduplicate
save `noduplicate'

*gen drop_duplicate=duplicate==1

di _N //18,321
 
*************************************************
*Drop 2: Survey taken not in the U.S.
*************************************************
*GEO CODE data to get the states of residence from lat/long 
*************************************************
*************************************************
*NOTE: Takes a while to do...connects to API for each obs
*Geocode Key = da3d46962e8c45feaed0292ac509222d

foreach z of numlist 1/11 {
import excel using "Qualtrics`date'/geo`z'.xlsx", clear firstrow
tempfile geo`z'
save `geo`z''
}
use `geo1', replace
append using `geo2'
append using `geo3'
append using `geo4'
append using `geo5'
append using `geo6'
append using `geo7'
append using `geo8'
append using `geo9'
append using `geo10'
append using `geo11'
bysort aid: keep if _n==1
drop locationlatitude locationlongitude
tempfile geo
save `geo'

*Merge Geo Data to Full Data*
use `noduplicate', replace
merge m:1 aid using `geo'
keep if _m==3
drop _m

*Drop if person is outside U.S. given their IP address*
tab g_country

*Need to do geocoding in batches because of limits per day from api key
preserve
keep if _merge==1 
keep aid locationlatitude locationlongitude

foreach z of numlist 1 {
if ${geo`z'} ==1 {
opencagegeo if _n>=(`z'-1)*2500 & _n<(`z')*2500, ///
	key(da3d46962e8c45feaed0292ac509222d) ///
	latitude(locationlatitude) longitude(locationlongitude)
keep if g_country!=""
export excel using "Qualtrics`date'/geo11.xlsx", firstrow(variables) replace
}
}
restore

*When All GeoCoding is done - append files and merge back to data!*

*Create A Variable for Geographic Division (Census Definition) Groups of States*
label define georegion 1 "Northeast" 2 "Midwest" 3 "South" 4 "West"
label define geodivision 1 "New England" 2 "Mid-Atlantic" 3 "East North Central" ///
	4 "West North Central" 5 "South Atlantic" 6 "East South Central" ///
	7 "West South Central" 8 "Mountain" 9 "Pacific"

gen geodivision=.
gen georegion=.
label variable geodivision "U.S. Geographic Division"
foreach s in "Connecticut" "Maine" "Massachusetts" "New Hampshire" "Vermont" ///
	"Rhode Island" {
	replace geodivision=1 if g_state=="`s'"
	replace georegion=1 if geodivision==1
	}
foreach s in "New Jersey" "New York" "Pennsylvania" {
	replace geodivision=2 if g_state=="`s'"
	replace georegion=1 if geodivision==2
	}
foreach s in "Illinois" "Indiana" "Michigan" "Wisconsin" "Ohio" {
	replace geodivision=3 if g_state=="`s'"
	replace georegion=2 if geodivision==3
	}
foreach s in "Iowa" "Kansas" "Minnesota" "Missouri" "Nebraska" "North Dakota" "South Dakota" {
	replace geodivision=4 if g_state=="`s'"
	replace georegion=2 if geodivision==4
	}
foreach s in "Delaware" "Florida" "Georgia" "Maryland" "District of Columbia" ///
	"North Carolina" "South Carolina" "Virginia" "West Virginia" "Puerto Rico" {
	replace geodivision=5 if g_state=="`s'"
	replace georegion=3 if geodivision==5
	}
foreach s in "Alabama" "Kentucky" "Mississippi" "Tennessee" {
	replace geodivision=6 if g_state=="`s'"
	replace georegion=3 if geodivision==6
	}
foreach s in "Arkansas" "Louisiana" "Oklahoma" "Texas" {
	replace geodivision=7 if g_state=="`s'"
	replace georegion=3 if geodivision==7
	}
foreach s in "Arizona" "Colorado" "Idaho" "Montana" "Nevada" "New Mexico" ///
	"Utah" "Wyoming" {
	replace geodivision=8 if g_state=="`s'"
	replace georegion=4 if geodivision==8
	}
foreach s in "Alaska" "California" "Hawaii" "Oregon" "Washington" {
	replace geodivision=9 if g_state=="`s'"
	replace georegion=4 if geodivision==9
	}	
label values geodivision geodivision
label values georegion georegion

gen drop_us=g_country!="United States"


***************************************************************************
*																		   *
*** 						Recode data                         	   *
*																		   *
***************************************************************************
  
 
*** 1.1 Demographic data         ***
label variable q41 "Sex"
replace q41="1" if q41=="Female"
replace q41="0" if q41=="Male"
replace q41="2" if q41=="Other"
destring q41, replace
label define gender 1 "Female" 0 "Male" 2 "Other"
label values q41 gender
rename q41 gender 

label variable q42 "Race"
replace q42="1" if q42=="White or Caucasian"
replace q42="2" if q42=="Black or African American"
replace q42="3" if q42=="Hispanic or Latino/Latinx"
replace q42="4" if q42=="Asian or Pacific Islander"
replace q42="5" if q42=="Other"
destring q42, replace
label define race 1 "White or Caucasian" 2 "Black or African American" 3 "Hispanic or Latino/Latinx" 4 "Asian or Pacific Islander" 5 "Other"
label values q42 race
rename q42 race

label variable q43 "Age group"
replace q43="1" if q43=="18 - 24 years old"
replace q43="2" if q43=="25 - 34 years old"
replace q43="3" if q43=="35 - 44 years old"
replace q43="4" if q43=="45 - 54 years old"
replace q43="5" if q43=="55 - 64 years old"
replace q43="6" if q43=="65 - 74 years old"
replace q43="7" if q43=="75 years or older"
destring q43, replace
label define age 1 "18-24 years" 2 "25-34 years" 3 "35-44 years" ///
	4 "45-54 years" 5 "55-64 years" 6 "65-74 years" 7 "75+ years"
label values q43 age
rename q43 agegroup

label variable q44 "Education level"
replace q44="1" if q44=="College degree or higher"
replace q44="2" if q44=="Some College"
replace q44="3" if q44=="High School degree / GED"
replace q44="4" if q44=="Less than High School"
label define education 1 "College degree or higher" 2 "Some College" ///
	3 "High School degree / GED" 4 "Less than High School"
destring q44, replace
label values q44 education
rename q44 educgroup

label variable q45 "Employment status"
replace q45="1" if q45=="Full-time employee"
replace q45="2" if q45=="Part-time employee"
replace q45="3" if q45=="Self-employed or small business owner"
replace q45="4" if q45=="Not employed"
label define employee 1 "Full-time employee" 2 "Part-time employee" ///
	3 "Self-employed or small business owner" 4 "Not employed"
destring q45, replace
label values q45 employee
rename q45 workgroup

label define yesno 1 "Yes" 0 "No", add

label variable q46 "Born in the US"
replace q46="1" if q46=="Yes"
replace q46="0" if q46=="No"
destring q46, replace
label values q46 yesno
rename q46 born_in_us

label variable q61 "Voted last election"
replace q61="1" if q61=="Yes"
replace q61="0" if q61=="No"
destring q61, replace
label values q61 yesno
rename q61 voted2016

label variable q62 "2016: Candidate Support"
replace q62="1" if q62=="Donald Trump" | q63=="Donald Trump"
replace q62="2" if q62=="Hillary Clinton" | q63=="Hillary Clinton"
replace q62="3" if q62=="Gary Johnson" | q62=="Jill Stein" ///
	| q63=="Gary Johnson" | q63=="Jill Stein"
replace q63="1" if q62=="Donald Trump" | q63=="Donald Trump"
replace q63="2" if q62=="Hillary Clinton" | q63=="Hillary Clinton"
replace q63="3" if q62=="Gary Johnson" | q62=="Jill Stein" ///
	| q63=="Gary Johnson" | q63=="Jill Stein"
destring q62, replace
destring q63, replace
label define candidate2016 1 "Donald Trump" 2 "Hillary Clinton" 3 "Other"
label values q62 candidate2016
label values q63 candidate2016
rename q62 candidate2016
replace candidate2016=q63 if candidate2016==. & q63!=.
drop q63

************************************************
*Drop 3: Quality Check - Weather & Immigration*
************************************************
*** Weather Attention Clip ***
*Drop Low Quality Responses*
rename q81_clickcount weather_clickcount
drop q81*
gen weather_right1=q91=="Weather Forecast"
gen weather_right2=q101=="Pleasant Weather (Sunny and Warm)"
drop q91 q101
tab weather_right1 weather_right2

preserve
keep if weather_right1==0 | weather_right2==0
keep aid mturk
export excel using "Qualtrics`date'/AudioTestWrong_Weather_`date'.xlsx", firstrow(variables) replace
restore

//2,618 out of 11,367 people get this wrong!
*drop if weather_right1==0 | weather_right2==0
gen drop_weather=weather_right1==0 | weather_right2==0

di _N //14,024

***1.2 Pre intervention beliefs ****

***IMMIGRATION VIEWS QUESTIONS
label variable q111 "Pre: Level of Immigration"
replace q111="5" if q111=="Decreased"
replace q111="1" if q111=="Increased"
replace q111="3" if q111=="Present level"
replace q111="3" if q111=="No Opinion" | q111=="No opinion"
destring q111, replace
label define increase 1 "Increased"  3 "Present level" 5 "Decrease", add
label values q111 increase
rename q111 pre_immlevel5

*CREATE GUN INDEX: Higher value is less gun control 
label variable q112 "Pre: Gun Index" 
replace q112="5" if q112=="Less strict"
replace q112="1" if q112=="More strict"
replace q112="3" if q112=="Kept as they are now"
replace q112="3" if q112=="No opinion"
label define gun 1 "More Strict" 3 "Kept as they are now"  5 "Less Strict" , add
destring q112, replace
label values q112 gun
rename q112 pre_gun_index5

*Create Abortion Index*
*Higher value for conservative position
label variable q113 "Pre: Abortion Index"
replace q113="5" if q113=="Illegal in all circumstances"
replace q113="1" if q113=="Legal under any circumstances"
replace q113="3" if q113=="Legal only under certain circumstances"
replace q113="3" if q113=="No opinion"
label define abortion 1 "Legal in all circumstances" 3 "Legal only under certain circumstances"  5 "Illegal in all circumstances" , add
destring q113, replace
label values q113 abortion
rename q113 pre_abortion_index5

*Create Tax Index*
//Support lower taxes for rich and higher taxes for poor is conservative
label variable q114 "Pre: Tax Index"
replace q114="5" if q114=="Too high"
replace q114="1" if q114=="Too low"
replace q114="3" if q114=="About right"
replace q114="3" if q114=="No opinion"
label define tax 1 "Too low" 3 "About right"  5 "Too high" , add
destring q114, replace
label values q114 tax
rename q114 pre_tax_index5

*Create Healthcare Index*
//Limited govt intervention is conservative
label variable q115 "Pre: Health Index"
replace q115="5" if q115=="No, it is not the government's responsibility"
replace q115="1" if q115=="Yes, it is the government's responsibility"
replace q115="3" if q115=="No opinion"
label define health 1 "Yes, government responsibility" 5 "No, not government responsibility" 3 "No opinion" , add
destring q115, replace
label values q115 health
rename q115 pre_health_index5

*Most Important Issue*
gen topissue_type=1 if q116=="Immigration"
replace topissue_type=2 if q116=="Abortion"
replace topissue_type=3 if q116=="Gun Control"
replace topissue_type=4 if q116=="Healthcare"
replace topissue_type=5 if q116=="Taxes"
label define topissue 1 "Immigration" 2 "Abortion" 3 "Gun Control" 4 "Healthcare" 5 "Taxes"
label values topissue_type topissue
drop q116

*****1.3 News consumption *******

label variable q121_1 "Facebook"
label variable q121_2 "Newspaper (Web or Print)"
label variable q121_3 "TV"
label variable q121_4 "Twitter"
label variable q122_1 "Breitbart News"
label variable q122_2 "Fox News"
label variable q122_3 "MNBC"
label variable q122_4 "Buzzfeed"
label variable q122_5 "The New York Times"
label define time_freq 0 "Never"  1 "Occasionally" 2 "Weekly" 3 "Daily", add
foreach var in q121_1 q121_2 q121_3 q121_4 q122_1 q122_2 q122_3 q122_4 q122_5 {
replace `var'="0" if `var'=="Never"
replace `var'="1" if `var'=="Occasionally"
replace `var'="2" if `var'=="Weekly"
replace `var'="3" if `var'=="Daily"
destring `var', replace
label values `var' time_freq
}
rename q121_1 freq_facebook
rename q121_2 freq_newspaper
rename q121_3 freq_tv
rename q121_4 freq_twitter
rename q122_1 freq_breitbart
rename q122_2 freq_fox
rename q122_3 freq_msnbc
rename q122_4 freq_buzzfeed 
rename q122_5 freq_nytimes

****** 1.4 Celebrities **********
label variable q131_1 "LeBron James"
label variable q131_2 "Barack Obama"
label variable q131_3 "Donald Trump"
label variable q131_4 "Bill Gates"
label variable q131_5 "Ellen DeGeneres"
label variable q131_6 "Taylor Swift"
label variable q131_7 "Kim Kardashian West"
label define star 2 "Fan" 1 "No opinion" 0 "Not Fan"
foreach var of varlist q131_1-q131_7 {
replace `var'="0" if `var'=="No, not a fan"
replace `var'="1" if `var'=="No Opinion"
replace `var'="2" if `var'=="Yes, a fan"
destring `var', replace
label values `var' star
}
rename q131_1 fan_lebronjames
rename q131_2 fan_obama
rename q131_3 fan_trump
rename q131_4 fan_billgates
rename q131_5 fan_ellendegeneres
rename q131_6 fan_taylorswift
rename q131_7 fan_kimkardashian


************************************
************************************
****** 2.  Create treatmet variables ******
************************************
************************************

gen treatment=. 
replace treatment=1 if q141_firstclick!="" 
replace treatment=2 if q151_firstclick!="" 
replace treatment=3 if q161_firstclick!="" 
replace treatment=4 if q171_firstclick!="" 
replace treatment=5 if q181_firstclick!="" 
replace treatment=6 if q191_firstclick!="" 
replace treatment=7 if q201_firstclick!="" 
replace treatment=8 if q211_firstclick!="" 
replace treatment=9 if q221_firstclick!="" 
replace treatment=10 if q231_firstclick!="" 
replace treatment=0 if q241_firstclick!="" 
label define treatment ///
	0 "Control Group" ///
	1 "Trump Trump Pro" ///
	2 "Obama Obama Pro" ///
	3 "Trump Actor Pro" ///
	4 "Obama Actor Pro" ///
	5 "Trump Trump Anti" ///
	6 "Obama Obama Anti" ///
	7 "Trump Actor Anti" ///
	8 "Obama Actor Anti" ///
	9 "Trump Turkey" ///
	10 "Obama Turkey" 
label values treatment treatment
gen drop_treat=treatment==.

//Exclude if people click a crazy amount of times during the intervention
gen clickcount=.
destring *_clickcount, replace                                                          
foreach x in 141 151 161 171 181 191 201 211 221 231 241 {
	replace clickcount=q`x'_clickcount if clickcount==.
	}
*drop if clickcount>10
drop q141_firstclick-q241_clickcount

************************************
************************************
******Post intervention ************
************************************
************************************

rename q251 candidate2020
label variable candidate2020 "2020: Candidate Support"
replace candidate2020="5" if candidate2020=="Donald Trump (Republican Candidate)"
replace candidate2020="1" if candidate2020=="Joe Biden (Democratic Candidate)"
replace candidate2020="3" if candidate2020=="Other"
destring candidate2020, replace
label define candidate2020 1 "Joe Biden" 5 "Donald Trump" 3 "Other"
label values candidate2020 candidate2020

label define favor_anti 5 "Strongly Favor" 4 "Favor" 3 "No opinion" 2 "Oppose" 1 "Strongly Oppose"
label define favor_pro  1 "Strongly Favor" 2 "Favor" 3 "No opinion" 4 "Oppose" 5 "Strongly Oppose"

label variable q261 "Post: Build Border Wall"
replace q261="5" if q261=="Strongly Favor"
replace q261="4" if q261=="Favor"
replace q261="3" if q261=="No opinion"
replace q261="2" if q261=="Oppose"
replace q261="1" if q261=="Strongly Oppose"
destring q261, replace
label values q261 favor_anti
rename q261 post_borderwall5

label variable q262 "Post: Hire Border Patrol Agents"
replace q262="5" if q262=="Strongly Favor"
replace q262="4" if q262=="Favor"
replace q262="3" if q262=="No opinion"
replace q262="2" if q262=="Oppose"
replace q262="1" if q262=="Strongly Oppose"
destring q262, replace
label values q262 favor_anti
rename q262 post_borderpatrol5

label variable q263 "Post: Check Employee Immigration Status"
replace q263="5" if q263=="Strongly Favor"
replace q263="4" if q263=="Favor"
replace q263="3" if q263=="No opinion"
replace q263="2" if q263=="Oppose"
replace q263="1" if q263=="Strongly Oppose"
destring q263, replace
label values q263 favor_anti
rename q263 post_checkworkerimmstatus5

label variable q264 "Post: Deport All Undocumented Immigrants"
replace q264="5" if q264=="Strongly Favor"
replace q264="4" if q264=="Favor"
replace q264="3" if q264=="No opinion"
replace q264="2" if q264=="Oppose"
replace q264="1" if q264=="Strongly Oppose"
destring q264, replace
label values q264 favor_anti
rename q264 post_deportall5

label variable q265 "Post: Deport Undocumented Immigrants with Criminal Record"
replace q265="5" if q265=="Strongly Favor"
replace q265="4" if q265=="Favor"
replace q265="3" if q265=="No opinion"
replace q265="2" if q265=="Oppose"
replace q265="1" if q265=="Strongly Oppose"
destring q265, replace
label values q265 favor_anti
rename q265 post_deportcrimerecord5 //Ambiguous interpretation - try leaving out

label variable q266 "Post: Path to Citizenship"
replace q266="1" if q266=="Strongly Favor"
replace q266="2" if q266=="Favor"
replace q266="3" if q266=="No opinion"
replace q266="4" if q266=="Oppose"
replace q266="5" if q266=="Strongly Oppose"
destring q266, replace
label values q266 favor_pro
rename q266 post_pathtocitizen5

label variable q267 "Post: Dreamer Path to Citizenship"
replace q267="1" if q267=="Strongly Favor"
replace q267="2" if q267=="Favor"
replace q267="3" if q267=="No opinion"
replace q267="4" if q267=="Oppose"
replace q267="5" if q267=="Strongly Oppose"
destring q267, replace
label values q267 favor_pro
rename q267 post_dreamerpathtocitizen5

label define contribution 5 "Negative" 3 "Neutral" 1 "Positive"

label variable q271_1 "Post: Dreamer Contribution"
label variable q271_2 "Post: Spanish Speaker Contribution"
label variable q271_3 "Post: English Speaker Contribution"
label variable q271_4 "Post: Legal Immigrant Contribution"
label variable q271_5 "Post: Illegal Immigrant Contribution"

foreach v of varlist q271_1-q271_5 {
replace `v'="1" if `v'=="Positive"
replace `v'="3" if `v'=="Neutral" | `v'=="No Opinion"
replace `v'="5" if `v'=="Negative"
destring `v', replace
label values `v' contribution
}

rename q271_1 post_contribdreamer5
rename q271_2 post_contribspanish5
rename q271_3 post_contribenglish5 //Given different name to exclude - interpretation ambiguous
rename q271_4 post_contriblegal5 //Given different name to exclude - interpretation ambiguous
rename q271_5 post_contribillegal5

label variable q281 "Post: Level of Immigration"
replace q281="5" if q281=="Decreased"
replace q281="1" if q281=="Increased"
replace q281="3" if q281=="Present level"
replace q281="3" if q281=="No Opinion" | q281=="No opinion"
destring q281, replace
label values q281 increase
rename q281 post_immlevel5

label variable q282 "Post: Immigrant Economic Impact"
replace q282="5" if q282=="Positive"
replace q282="3" if q282=="Neither positive or negative" | q282=="No opinion"
replace q282="1" if q282=="Negative"
destring q282, replace
label values q282 contribution
rename q282 post_economicimpact5

label define yesno2 5 "Yes" 3 "No opinion" 1 "No"

label variable q283 "Post: Immigrant Crime Share"
replace q283="1" if q283=="No"
replace q283="3" if q283=="No opinion"
replace q283="5" if q283=="Yes"
destring q283, replace
label values q283 yesno2
rename q283 post_crimeshare5

gen overallopinion=q291_1
replace overallopinion=q292_1 if overallopinion==""
destring overallopinion, replace
*Change so 100 is anti - flip scale*
replace overallopinion=-1*overallopinion
//gen rescaled version for index
gen post_overall5=1+(100+overallopinion)/50 
drop q291_1 q292_1

gen charityscale=.
label var charityscale "Charity Donation Scale"
replace charityscale=5 if strpos(q302,"FAIR")>0 & q303=="Yes"
replace charityscale=4 if strpos(q302,"FAIR")>0 & q303=="No"
replace charityscale=3 if q302=="I prefer not to donate to either charity"
replace charityscale=2 if strpos(q302,"ACLU")>0 & q303=="No"
replace charityscale=1 if strpos(q302,"ACLU")>0 & q303=="Yes"
label define charity 1 "ACLU - Share" 2 "ACLU - No Share" 3 "No Charity" 4 "FAIR - No Share" 5 "FAIR - Share"
label values charityscale charity
drop q302 q303
rename charityscale charityscale5

rename q304_1 charitydonation
destring charitydonation, replace

************************************************
*Drop 3B: Quality Check - Audio Treatment - Immigration/Turkey*
************************************************

gen immigration_right=0 if treatment>=1 & treatment<=8
replace immigration_right=1 if q331=="Immigration" 
gen turkey_right=0 if treatment>=9
replace turkey_right=1 if q341=="Thanksgiving"
drop q331 q341

tab turkey_right
tab immigration_right 

if $emily ==1  {
preserve
keep if turkey_right==0 | immigration_right==0
keep aid mturk
export excel using "Qualtrics`date'/AudioTestWrong_TurkeyorImmigration_`date'.xlsx", firstrow(variables) replace
restore
}

gen drop_contentpost=(turkey_right==0 | immigration_right==0)
*drop if turkey_right==0 | immigration_right==0 

di _N //13,578

***********************************

*Perception Source/Content*
gen dummy_source_obama=q351=="Barack Obama"
gen dummy_source_trump=q351=="Donald Trump"
gen dummy_source_clinton=q351=="Bill Clinton"
gen dummy_source_bush=q351=="George W. Bush"

gen dummy_source_dem=dummy_source_obama==1 | q351=="Bill Clinton"
gen dummy_source_rep=dummy_source_trump==1 | q351=="George W. Bush"

drop q351
destring q361_1 q362_1, replace
gen prob_source_obama=q361_1
replace prob_source_obama=100-q362_1 if prob_source_obama==.
gen prob_source_trump=100-prob_source_obama
drop q361_1 q362_1

destring q371_1 q372_1, replace
gen prob_content_anti=q371_1
replace prob_content_anti=100-q372_1 if prob_content_anti==.
gen prob_content_pro=100-prob_content_anti
drop q371_1 q372_1


***********************************************************
*Drop 5: Remaining Inconsistencies with CloudResearch Data*
***********************************************************

if $emily ==1  {
preserve
clear
import delimited "Qualtrics`date'/PrimePanels_Status_IDs_11_30_20.csv", varnames(1) 
keep aid ipaddress info
tempfile cloudresearch
save `cloudresearch'
restore
}
gen ipaddress_short = substr(ipaddress, 1, 20)
rename ipaddress  ipaddresslong
rename ipaddress_short ipaddress 
merge 1:m aid ipaddress using `cloudresearch'
drop if _m==2
drop if info=="CR Status - Security Term / Duplicate AID"
sort aid startdate
bysort aid: keep if _n==1
drop info ipaddress _m

******************************
*TIME AND PSCORE RESTRICTIONS*
******************************

*Cut observations that are not within reasonable time*
destring durationinseconds, replace
gen timesurvey=durationinseconds if treatment==0
replace timesurvey=durationinseconds-205 if treatment==1
replace timesurvey=durationinseconds-146 if treatment==2
replace timesurvey=durationinseconds-161 if treatment==3
replace timesurvey=durationinseconds-134 if treatment==4
replace timesurvey=durationinseconds-195 if treatment==5
replace timesurvey=durationinseconds-174 if treatment==6
replace timesurvey=durationinseconds-135 if treatment==7
replace timesurvey=durationinseconds-159 if treatment==8
replace timesurvey=durationinseconds-123 if treatment==9
replace timesurvey=durationinseconds-97 if treatment==10

//Participants must spend at least 5 minutes - Approx 5th percentile
gen timeminutes=timesurvey/60
sum timeminutes, d
sum timesurvey, d

gen timegood=timesurvey>=240 & timesurvey<=2700

gen drop_time=timegood==0

************************
*CREATE SET OF OUTCOMES*
************************

*Convert Overall Opinion to be Out of 0/1 - then log transformed (same scale)*
rename overallopinion overallopinion_raw
gen prob_opinion_anti=0.5+overallopinion_raw/200
gen prob_opinion_pro=1-prob_opinion_anti
gen ln1_prob_opinion_anti=ln(prob_opinion_anti+1)
gen ln1_prob_opinion_pro=ln(prob_opinion_pro+1)

*Indicator - Level Increase/Decrease*
gen prob_level_anti=post_immlevel5==5
replace prob_level_anti=0.5 if post_immlevel5==3
gen prob_level_pro=1-prob_level_anti
gen ln1_prob_level_anti=ln(prob_level_anti+1)
gen ln1_prob_level_pro=ln(prob_level_pro+1)

*Indicator - Crime Share*
gen prob_crime_anti=post_crimeshare5==5
replace prob_crime_anti=0.5 if post_crimeshare5==3
gen prob_crime_pro=1-prob_crime_anti
gen ln1_prob_crime_anti=ln(prob_crime_anti+1)
gen ln1_prob_crime_pro=ln(prob_crime_pro+1)

*Indicator - Vote - Define only for pre-election*
gen beforevote=(date!="11-03" & date!="11-04" & date!="11-05" & date!="11-06" ///
	& date!="11-07"	& date!="11-08" & date!="11-09" & date!="11-10" )
gen prob_vote_anti=candidate2020==5 & beforevote==1 & candidate2020!=.
replace prob_vote_anti=0.5 if candidate2020==3 & beforevote==1 
gen prob_vote_pro=1-prob_vote_anti if beforevote==1
gen ln1_prob_vote_anti=ln(prob_vote_anti+1) if beforevote==1
gen ln1_prob_vote_pro=ln(prob_vote_pro+1) if beforevote==1
gen post_vote5=1+prob_vote_anti*4 if beforevote==1

*Indicator - Charity - Donation* 
gen canti=charityscale5>3
gen cpro=charityscale5<3
replace charitydonation=0 if charitydonation==. & charityscale5!=.
gen prob_charity_anti=0.5+canti*charitydonation/50-cpro*charitydonation/50
gen prob_charity_pro=1-prob_charity_anti
gen ln1_prob_charity_anti=ln(prob_charity_anti+1)
gen ln1_prob_charity_pro=ln(prob_charity_pro+1)

*Generate -1/0/1 version of questions*
*Pro/Anti versions are out of 0-1 with 0.5 as a value for neutral
foreach x in pre_immlevel pre_gun_index pre_health_index ///
	pre_tax_index pre_abortion_index ///
	post_borderwall post_borderpatrol ///
	post_checkworkerimmstatus post_deportall post_deportcrimerecord ///
	post_pathtocitizen post_dreamerpathtocitizen post_contribdreamer ///
	post_contribspanish post_contribenglish post_contriblegal ///
	post_contribillegal post_immlevel post_economicimpact ///
	post_crimeshare post_overall charityscale {
		gen `x'_pro=`x'5<3
		replace `x'_pro=0.5 if `x'5==3
		gen `x'_anti=1-`x'_pro
		gen `x'_prox=`x'5<4
		replace `x'_prox=0.75 if `x'5==4
		replace `x'_prox=0.5 if `x'5==3
		replace `x'_prox=0.25 if `x'5==2
		gen `x'_antix=1-`x'_prox
		rename `x'5 `x'_raw5
	}
	

*Raw 1-5 Index*
egen i5=rowtotal(post*raw5)
gen index_anti_raw5=i5/16 //1 to 5 version

*Baseline Index*
egen p=rowtotal(post*pro)
gen prob_index_pro=(p)/16 //0 to 1 version
gen prob_index_anti=1-prob_index_pro //0 to 1 version
drop p i5

*Fully graded version
egen p=rowtotal(post*prox)
gen prob_index_prox=(p)/16 //0 to 1 version
gen prob_index_antix=1-prob_index_prox //0 to 1 version
rename prob_index_prox prob5_index_pro
rename prob_index_antix prob5_index_anti
drop p *prox *antix

*Index - 14 Question Version - Pre-registered*
gen prob14_index_pro=(prob_index_pro*16-post_contribenglish_pro-post_contriblegal_pro)/14
gen prob14_index_anti=1-prob14_index_pro

*Create Sample Restriction Variable*
//List Predictors
global covar2 i.gender i.race i.agegroup i.educgroup i.workgroup i.democrat ///
	i.voted2016 i.candidate2016 i.pre_immlevel_raw5 i.pre_gun_index_raw5 i.pre_abortion_index_raw5 ///
	i.pre_tax_index_raw5 i.pre_health_index_raw5 i.freq_facebook i.freq_twitter ///
	i.freq_tv i.freq_newspaper i.freq_fox i.freq_msnbc i.freq_breitbart ///
	i.freq_buzzfeed i.freq_nytimes i.fan_obama i.fan_trump i.fan_lebronjames ///
	i.fan_billgates i.fan_ellendegeneres i.fan_taylorswift i.fan_kimkardashian ///
	i.georegion i.born_in_us weather_clickcount i.topissue_type 

gen president=treatment==1 | treatment==2 | treatment==5 | treatment==6

reg president  $covar2
gen drop_missing=e(sample)==0 //93 people have some missing responses in pre-treatment
drop president

gen sample=drop_consent==0 & drop_audio==0 & drop_citizen==0 & drop_treat==0 ///
	& drop_us==0 & drop_inconsistent==0 & drop_weather==0 ///
	& drop_contentpost==0 & drop_time==0 & drop_missing==0 
	
*NORMED INDICES*
*Including Anderson 2008 Version*
*Inverse Covariance Weighted - Normed Index*

*Standardized Average Index - with respect to control group and party
foreach x in anti pro {
sum prob_index_`x' if recruit==0 & treat==0 & sample==1
gen probst_index_`x'=(prob_index_`x'-r(mean))/r(sd) if recruit==0 & sample==1
sum prob_index_`x' if recruit==1 & treat==0 & sample==1
replace probst_index_`x'=(prob_index_`x'-r(mean))/r(sd) if recruit==1 & sample==1
}		

*Anderson(2008) version of Index*
gen c1=treat==0 & recruit==1 & sample==1
gen c2=treat==0 & recruit==0 & sample==1

rename post_checkworkerimmstatus_* post_checkworker_*
rename post_dreamerpathtocitizen_* post_dreamerpath_*
rename post_deportcrimerecord_* post_deportcrime_*

*Normed Version*
swindex post_borderwall_pro post_borderpatrol_pro ///
	post_checkworker_pro post_deportall_pro post_deportcrime_pro ///
	post_pathtocitizen_pro post_dreamerpath_pro post_contribdreamer_pro ///
	post_contribspanish_pro post_contribenglish_pro post_contriblegal_pro ///
	post_contribillegal_pro post_immlevel_pro post_economicimpact_pro ///
	post_crimeshare_pro post_overall_pro if recruit==1 & sample==1, normby(c1) gen(probst_anderson_pro)

swindex post_borderwall_anti post_borderpatrol_anti ///
	post_checkworker_anti post_deportall_anti post_deportcrime_anti ///
	post_pathtocitizen_anti post_dreamerpath_anti post_contribdreamer_anti ///
	post_contribspanish_anti post_contribenglish_anti post_contriblegal_anti ///
	post_contribillegal_anti post_immlevel_anti post_economicimpact_anti ///
	post_crimeshare_anti post_overall_anti if recruit==0 & sample==1, normby(c2) gen(probst_anderson_anti)	

*Un-normed Version*
swindex post_borderwall_pro post_borderpatrol_pro ///
	post_checkworker_pro post_deportall_pro post_deportcrime_pro ///
	post_pathtocitizen_pro post_dreamerpath_pro post_contribdreamer_pro ///
	post_contribspanish_pro post_contribenglish_pro post_contriblegal_pro ///
	post_contribillegal_pro post_immlevel_pro post_economicimpact_pro ///
	post_crimeshare_pro post_overall_pro if recruit==1 & sample==1, nostd gen(prob_anderson_pro)

swindex post_borderwall_anti post_borderpatrol_anti ///
	post_checkworker_anti post_deportall_anti post_deportcrime_anti ///
	post_pathtocitizen_anti post_dreamerpath_anti post_contribdreamer_anti ///
	post_contribspanish_anti post_contribenglish_anti post_contriblegal_anti ///
	post_contribillegal_anti post_immlevel_anti post_economicimpact_anti ///
	post_crimeshare_anti post_overall_anti if recruit==0 & sample==1, nostd gen(prob_anderson_anti)		

rename post_checkworker_* post_checkworkerimmstatus_* 
rename post_dreamerpath_* post_dreamerpathtocitizen_* 
rename post_deportcrime_* post_deportcrimerecord_* 
drop c1 c2

**Sub-Indices - Beliefs vs. Policies**
/**Beliefs - 9 questions**
post_contribdreamer
post_contribspanish
post_contribenglish
post_contriblegal
post_contribillegal
post_immlevel
post_economicimpact
post_crimeshare 
post_overall
*/

global beliefpro ""

foreach x in post_contribdreamer post_contribspanish post_contribenglish ///
	post_contriblegal post_contribillegal post_immlevel post_economicimpact ///
	post_crimeshare post_overall {
	
	global beliefpro "`x'_pro $beliefpro"
	
	}

/**Policies - 7 questions**
post_borderwall 
post_borderpatrol
post_checkworkerimmstatus 
post_deportall 
post_deportcrimerecord 
post_pathtocitizen 
post_dreamerpathtocitizen 
*/

global policypro ""

foreach x in post_borderwall post_borderpatrol post_checkworkerimmstatus post_deportall ///
	post_deportcrimerecord post_pathtocitizen post_dreamerpathtocitizen {
	
	global policypro "`x'_pro $policypro"
	
	}
	
egen pol=rowtotal($policypro )
gen prob_policy_pro=(pol)/7 //0 to 1 version
gen prob_policy_anti=1-prob_policy_pro //0 to 1 version
egen bel=rowtotal($beliefpro )
gen prob_belief_pro=(bel)/9 //0 to 1 version
gen prob_belief_anti=1-prob_belief_pro //0 to 1 version
drop pol bel
	

*Create Different Versions of Indices*
gen ln_prob_index_pro=ln(prob_index_pro) //log index probability (no +1)
gen ln_prob_index_anti=ln(prob_index_anti) //log index probability (no +1)
gen ln1_prob_index_pro=ln(prob_index_pro+1) //log index probability +1
gen ln1_prob_index_anti=ln(prob_index_anti+1) //log index probability +1
gen ln1_prob14_index_pro=ln(prob14_index_pro+1) //preregistered index
gen ln1_prob14_index_anti=ln(prob14_index_anti+1) //preregistered index
gen ln1_prob5_index_pro=ln(prob5_index_pro+1) //5 option version
gen ln1_prob5_index_anti=ln(prob5_index_anti+1) //5 option version
gen ln1_prob_policy_pro=ln(prob_policy_pro+1) //Policy Sub-Index
gen ln1_prob_policy_anti=ln(prob_policy_anti+1) //Policy Sub-Index
gen ln1_prob_belief_pro=ln(prob_belief_pro+1) //Policy Sub-Index
gen ln1_prob_belief_anti=ln(prob_belief_anti+1) //Policy Sub-Index
gen ln1_prob_anderson_pro=ln(prob_anderson_pro+1) //Log of Anderson version of index (not normed)
gen ln1_prob_anderson_anti=ln(prob_anderson_anti+1) //Log of Anderson version of index (not normed)


*Probability Convinced*
gen prob_convinced=prob_index_anti if treat>4 & treat<=8
replace prob_convinced=prob_index_pro if treat>0 & treat<=4
gen probst_convinced=probst_index_anti if treat>4 & treat<=8
replace probst_convinced=probst_index_pro if treat>0 & treat<=4
gen ln_convinced=ln_prob_index_anti if treat>4 & treat<=8
replace ln_convinced=ln_prob_index_pro if treat>0 & treat<=4
gen ln1_convinced=ln1_prob_index_anti if treat>4 & treat<=8
replace ln1_convinced=ln1_prob_index_pro if treat>0 & treat<=4
gen ln1_convinced5=ln1_prob5_index_anti if treat>4 & treat<=8
replace ln1_convinced5=ln1_prob5_index_pro if treat>0 & treat<=4
gen ln1_convinced14=ln1_prob14_index_anti if treat>4 & treat<=8
replace ln1_convinced14=ln1_prob14_index_pro if treat>0 & treat<=4


***************************************************
**COVARIATE SET***
***************************************************
gen female=gender==1
gen white=race==1
gen black=race==2
gen hispanic=race==3
gen asian=race==4
gen a_18_24=age==1
gen a_25_34=age==2
gen a_35_44=age==3
gen a_45_64=age==4 | age==5
gen a_65=age>5
gen collegeorhigher=educgroup==1
gen fulltimeemployed=workgroup==1
foreach x in facebook twitter tv newspaper fox msnbc {
	gen week_`x'=freq_`x'>2
}
gen independent=dem==2
gen voted=voted2016==1
gen trump2016=candidate2016==1
gen trumpfan=fan_trump==2
gen obamafan=fan_obama==2
gen pre_increase=pre_immlevel_raw5==1
gen pre_decrease=pre_immlevel_raw5==5
gen northeast=georegion==1
gen midwest=georegion==2
gen south=georegion==3
gen west=georegion==4

global covar female white black hispanic northeast midwest south ///
	a_18_24 a_25_34 a_45_64 collegeorhigher fulltimeemployed ///
	week_facebook week_twitter week_tv week_newspaper week_fox week_msnbc ///
	independent voted trump2016 trumpfan obamafan topissue_immigration ///
	pre_increase pre_decrease

*Carolina's Computer*
if $carolina ==1  {
cap cd "E:\Dropbox\Carolina-Emily-Project\Data\Study\"
}
*Emily's Computer*
if $emily ==1  {
cap cd "~/Dropbox/SourceContent/Data/Study/"
} 

	

save 1_clean_data, replace


//Save Approval IDs //
if $carolina ==1  {
preserve
keep aid mturk
export excel using "Qualtrics`date'/ApprovedIDs_`date'.xlsx", firstrow(variables) replace
restore
}
